import { Label, Prefab, Vec3, instantiate, resources, tween } from "cc";
import { gg } from "../Game";
import { setNodeScale } from "../../extensions/cocos-scaffold-3x/assets/common/Utils";

export function showToast(str: string) {
    resources.load("toast/toast", Prefab, (err, prefab) => {
        const node = instantiate(prefab)
        node.getComponentInChildren(Label).string = str
        gg.uiMgr.tipRoot.addChild(node)
        setNodeScale(node, 0)

        tween(node).to(0.2, { scale: new Vec3(1, 1, 1) }, { easing: "expoOut" }).delay(1).to(0.2, { scale: new Vec3(0, 0, 0) }, { easing: "expoOut" })
            .call(() => {
                node.destroy()
            })
            .start()
    })

}